<?php
class firstdata_ecommerce extends panel {
	var $name = 'Firstdata E-Commerce';
	
	public static function display() {
		global $cndb;
		if($_REQUEST['add_product']) {
			$insert = array('fdp_name'=>$_REQUEST['product_name'], 'fdp_description'=>$_REQUEST['product_description'], 'fdp_price'=>$_REQUEST['unit_price']);
			$cndb->insert('firstdata_products', $insert)
			?><p class="alert-success">Product added successfully.</p><?php
		}
		elseif($_REQUEST['firstdata_update']) {
			cn_set_option('firstdata_storenum', $_REQUEST['firstdata_storenum']);
			?><p class="alert-success">Store number set.</p><?php
		}
		?>
		<div class="two-column">
			<div class="box">
				<h3>Firstdata E-Commerce Configuration</h3>
				<div class="box-content">
					<form action="<?=$_SERVER['PHP_SELF']?><?=query_string()?>" method="post">
						<label>Your Store Number <input type="text" name="firstdata_storenum" value="<?=cn_get_option('firstdata_storenum')?>"/> </label>
						
						<input type="submit" value="Update Settings" class="small-button" name="firstdata_update"/>
						
					</form>
				</div>
			</div>
		</div>
		<div class="two-column">
			<div class="box">
				<h3>Add Product</h3>
				<form action="<?=$_SERVER['PHP_SELF']?><?=query_string()?>" method="post">
					<div class="box-content">
					<p>
						<label>Product Name</label>
						<input type="text" class="wide" name="product_name"/>
					</p>
					<p>
						<label>Product Description</label>
						<textarea name="product_description"></textarea>
					</p>
					<p>
						<label>Unit Price</label>
						<input type="text" class="thin" name="unit_price"/>
					</p>
					<input type="submit" class="small-button" name="add_product" value="Add Product"/>
					</div>
			</div>
		</div>
		<div class="clearboth"></div>
		<div class="one-column">
			
			<div class="box">
				<h3>Manage Products</h3>
				
				<table class="admin-table" width="100%">
					<thead>
						<tr>
							<th>ID</th>
							<th>Name</th>
							<th>Unit Price</th>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<th>ID</th>
							<th>Name</th>
							<th>Unit Price</th>
						</tr>
					</tfoot>
					<tbody>
						<?php $results = $cndb->get_results("SELECT * FROM `firstdata_products` ORDER BY `fdp_name`");?>
						<?php $style = ''; ?>
						<?php foreach($results as $result) : ?>
						
						<tr<?=$style?>>
							<td><?=$result->fdp_id?></td>
							<td><?=$result->fdp_name?></td>
							<td><?=$result->fdp_price?></td>
							
						</tr>
						<?php $style = ($style == ' class="alternate"') ? '' : ' class="alternate"';?>
						<?php endforeach;?>
					</tbody>
				</table>
			</div>
			<div class="box">
				<h3>View Transactions</h3>
				
				<form action="<?=$_SERVER['PHP_SELF']?><?=query_string()?>" method="post">
				<table class="admin-table" width="100%">
					<thead>
						<tr>
							<th>ID</th>
							<th>Date</th>
							<th>Name</th>
							<th>Card</th>
							<th>Amount</th>
						</tr>
					</thead>
					<tfoot>
						<tr>
							<th>ID</th>
							<th>Date</th>
							<th>Name</th>
							<th>Card</th>
							<th>Amount</th>
						</tr>
					</tfoot>
					<tbody>
						<?php $results = $cndb->get_results("SELECT * FROM `firstdata_records` ORDER BY `fdr_date`");?>
						<?php $style = ''; ?>
						<?php foreach($results as $result) : ?>
						
						<tr<?=$style?>>
							<td><?=$result->fdr_id?></td>
							<td><?=$result->fdr_timestamp?></td>
							<td><?=$result->fdr_name?></td>
							<td><?=$result->fdr_card?></td>
							<td><?=$result->fdr_amount?></td>
							
						</tr>
						<?php $style = ($style == ' class="alternate"') ? '' : ' class="alternate"';?>
						<?php endforeach;?>
					</tbody>
				</table>
			</div>
		</div>
	
		<?php
	}
}

?>